package com.cuiweiyou.bluemesh.util;

import android.app.NotificationManager;
import android.content.Context;

import com.cuiweiyou.bluemesh.R;
import com.cuiweiyou.bluemesh.base.BluetoothApp;
import com.cuiweiyou.bluemesh.model.NotificationModel;

import java.util.ArrayList;
import java.util.List;

public class NotificationUtil {

    private static NotificationUtil instance;
    private NotificationManager notificationManager;
    private List<NotificationModel> notificationList;

    private int notificationdId = 0;
    private String contentTitle = "回家模式已经开启：回调房屋附近时自动打开灯组照明"; // 通知标题
    private String contentText = "请勿从后台或最近任务中关闭应用";  // 通知内容
    private int icon = R.mipmap.ico_house;

    private Context context;

    private NotificationUtil() {
        notificationManager = (NotificationManager) BluetoothApp.getContext().getSystemService(Context.NOTIFICATION_SERVICE);
        notificationList = new ArrayList<>();
        context = BluetoothApp.getContext();
    }

    public static NotificationUtil getInstance() {
        if (null == instance) {
            synchronized (NotificationUtil.class) {
                if (null == instance) {
                    instance = new NotificationUtil();
                }
            }
        }
        return instance;
    }

    public void makeNotification() {
        NotificationModel notificationModel = new NotificationModel(notificationManager, context, notificationdId, contentTitle, contentText, icon);
        notificationList.add(notificationModel);

        notificationManager.notify(notificationdId, notificationModel.getNotification());

        notificationdId++;
    }

    public void clearAllNotification() {
        notificationManager.cancelAll();
    }

}
